'''
Author: NingJian
Date: 2021-07-28 09:35:45
LastEditTime: 2021-07-28 09:35:46
LastEditors: NingJian
Description: 
FilePath: /opencv-as-pillow-resize/test/test.py

'''

import os

import numpy as np

from PIL import Image

import torchvision.transforms as transforms

current_work_dir = os.path.dirname(__file__)

im = Image.open(os.path.join(current_work_dir,"im6.bmp"))
transform = transforms.Compose([
    transforms.Resize(256),
])


print(im.mode)

dn_im = np.array(im)
print(dn_im)
# [[[ 40  13   2]
#   [ 40   7   0]
#   [ 51  14   8]
#   ...
#   [106  90  65]
#   [114  96  74]
#   [111  79  64]]


data = transform(im)

print(data)  # image mode=RGB size=256x309


rim = im.resize((256,309), Image.BILINEAR)
rdn = np.array(rim)

print(rdn[0,:,:])

dn = np.array(data)

#print(dn)
# [[[ 41  11   1]
#   [ 46  10   4]
#   [ 48  11   5]
#   ...
#   [ 98  74  54]
#   [109  91  68]
#   [114  91  72]]

#  [[ 46  12   4]
#   [ 45  10   4]
#   [ 47  11   5]
#   ...
#   [100  76  55]
#   [113  95  72]
#   [120  98  81]]

#  [[ 48  10   4]
#   [ 46  11   5]
#   [ 46  11   5]
#   ...
#   [ 94  77  56]
#   [113  97  77]
#   [124 104  90]]

#  ...

#  [[118  93  60]
#   [120  98  63]
#   [126 101  68]
#   ...
#   [253 251 252]
#   [253 251 252]
#   [252 250 251]]

#  [[119  94  59]
#   [120 100  62]
#   [128 101  67]
#   ...
#   [253 251 252]
#   [253 251 252]
#   [252 250 251]]

#  [[117  94  56]
#   [120  99  59]
#   [128  99  66]
#   ...
#   [253 251 252]
#   [253 251 252]
#   [252 250 251]]]